(function(){
	let span = document.querySelector("body>div:first-child>span:last-child");
	span.addEventListener("click", ()=>open("register.html","_self"));
	let div = document.querySelector("body>div:nth-child(2)"),
		spans = document.querySelectorAll("body>div:nth-child(2)>span");
	div.addEventListener("click", function(e){
		var target = e.target;
		spans.forEach(val=>{
			val.style.color = "#666"
			val.style.borderBottom = "none";
		})
		target.style.color = "#00c2c3";
		target.style.borderBottom = ".02rem solid #00c2c3";
	})
	let iconspan = document.querySelector("body>div:first-child>span:first-child");
	iconspan.addEventListener("click", ()=>history.go(-1));

	// reg
	let myform = document.forms[0];
	let phoneReg = /^(\+86)?1[3-9][0-9]{9}$/;
	let pswReg = /^\w{8,16}$/;
	myform[0].oninput = function(){
		myform[0].maxLength = myform[0].value.indexOf("+86") != -1 ? "14" : "11";
		this.style.color = phoneReg.test(this.value) ?  "green" : "red";
	}
	myform[0].nextElementSibling.onclick = function(){
		if(phoneReg.test(myform[0].value)){
			var arr = [];
			for (var i = 48; i <= 122; i++) {
				(i<=57 || i>=65 && i<=90 || i>=97) && (arr[arr.length] = String.fromCharCode(i));
			}
			for (var i = 1,arr2 = []; i < 5; i++) {
				arr2.push(arr[parseInt(Math.random()*arr.length)]);
			}
			this.innerText = arr2.join("");
		}
	}
	myform[1].oninput = function(){
		myform[1].maxLength = "16";
		this.style.color = pswReg.test(this.value) ?  "green" : "red";
	}
	myform[2].oninput = function(){
		if(this.value.toUpperCase() == myform[0].nextElementSibling.innerText.toUpperCase() && this.value != "获取验证码"){
			this.style.color = "green";
		}else{
			this.style.color = "red";
		}
	}
	myform.onsubmit = function(){
		var n = 0
		for(let i = 0; i < myform.elements.length - 1; i++){
			myform.elements[i].style.color == "green" && n++;
		}
		if(n < myform.elements.length - 2){
			console.log(n);
			return false;
		}
	}
	let a = document.querySelector("body>a");
	if(sessionStorage.err){
		a.style.display = "block";
	}else{
		a.style.display = "none";
	}
	a.onclick = function(){
		this.style.display = "none";
	}
})()